package 力扣.双指针.双指针;

public class 子数组的最大平均值868 {
    public double findMaxAverage(int[] nums, int k) {
        if (nums == null || nums.length == 0){
            return 0;
        }
        double teans = 0.0;//使用double效率更高
        double ans = Double.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            int te = nums[i];
            teans += te;
            if (i < (k-1)){
                continue;
            }
            ans = Math.max(ans, Double.valueOf(teans) / k);
            teans -= nums[i - k + 1];
        }
        return ans;
    }
}
